package br.com.felix.fwt.ui;

import java.io.PrintWriter;

import br.com.felix.fwt.ui.exception.ComponentRenderException;

public class Link extends BaseComponent{

	private static final long serialVersionUID = -5803289628240282130L;
	
	{
		this.cssClass = "fwtlink";
	}
	
	private String label;

	
	/**
	 * Instantiates a new link.
	 * @param label is the link's label.
	 * @param url is the appointed link.
	 * */
	public Link(String label, String url){
        setValue(url);
        setLabel(label);
    }
	
	
	@Override
	public void write(PrintWriter out) throws ComponentRenderException {
		if(!authorized()) return;
		out.write(String.format("\n<a href=\"%s\"", getValue()));
		if(style!=null){
			out.write(style);
		}
		String name = getName();
		if(name!=null){
			out.write(" id=\"");
			out.write(name);
			out.write("\" ");
		}
		out.write(">\n");
		out.write(getLabel());
		out.write("\n</a>");
	}


	public String getLabel() {
		return label;
	}


	public void setLabel(String label) {
		this.label = label;
	}

}
